<%@ page language="java" isELIgnored="false" contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>

<html>
    <head>
        <title>Ajax json交互</title>
        <style>
            div{
                padding: 10px 10px 0 10px;
            }
        </style>
        <script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>
        <script type="text/javascript">
            $(function () {
                $("#ajaxBtn").bind("click",function () {
                    // 发送ajax请求
                    $.ajax({
                        url: '/demo/json',
                        type: 'POST',
                        data: '{"name":"李四","age":22}',
                        contentType: 'application/json;charset=utf-8',
                        dataType: 'json',
                        success: function (data) {
                            alert("姓名: " + data.name);
                            alert("年龄: " + data.age);
                        }
                    })
                })
            })
        </script>
    </head>
    <body>
        <div>
            <h3>Ajax json交互</h3>
            <fieldset>
                <input type="button" id="ajaxBtn" value="ajax提交"/>
            </fieldset>
        </div>
    </body>
</html>
